function GameEngine() {
	if(!GameEngine.instance) {
		GameEngine.instance = {
			level: 0, //游戏难度
			enemes: new Set(),
			body: document.getElementsByClassName("main")[0],
			start: function() { //游戏开始
				var count = 0;
				//背景移动
				setInterval(function() {
					this.body.style.backgroundPositionY = (count+=3) + "px";
				}.bind(this), 60);
				this.initMenu();
			},
			loading: function() { //载入动画
				var logo = document.createElement("div");
				var load = document.createElement("div");
				logo.className = "logo";
				load.className = "loading";

				//加入页面
				this.body.appendChild(logo);
				this.body.appendChild(load);

				var count = 1;
				var imgIndex = 1;
				var timer = setInterval(function() {
					load.style.background = "url(images/loading" + imgIndex++ + ".png)";
					if(imgIndex > 3) imgIndex = 1;
					if(++count == 5) {
						//真正的游戏开始
						this.realstart();
						logo.remove();
						load.remove();
						clearInterval(timer);
					}
				}.bind(this), 300);
			},
			initMenu: function() { //初始化菜单
				var menu = document.getElementsByClassName("options")[0];
				menu.addEventListener("click", function(e) {
					var e = e || event;
					var currentEle = e.target || e.srcElement;
					if(currentEle.tagName == "LI") {
						new GameEngine().level = currentEle.getAttribute("level");
						new GameEngine().loading();
						//把菜单清楚掉
						this.remove();
					}
				}, true);
			},
			realstart: function() { //游戏真正的开始
				new MyPlane().show();
				this.autoCreateEnemes();
			},
			autoCreateEnemes: function() { //自动创建敌人
				setInterval(function() {
					if(Math.random() > 0.2) {
						this.enemes.add(new Enemy("small").init().move());
					}
				}.bind(this), 500);
				setInterval(function() {
					if(Math.random() > 0.35) {
						this.enemes.add(new Enemy("middle").init().move());
					}
				}.bind(this), 3000);
				setInterval(function() {
					if(Math.random() > 0.7) {
						this.enemes.add(new Enemy("large").init().move());
					}
				}.bind(this), 8000);
			},
			width: function() {
				return this.body.offsetWidth;
			},
			height: function() {
				return this.body.offsetHeight;
			},
			left: function() {
				return this.body.offsetLeft;
			},
			append: function(p) {
				this.body.appendChild(p.body);
			}
		}
	}
	return GameEngine.instance;
}